<%--
  Created by IntelliJ IDEA.
  User: 26423
  Date: 2021/6/16
  Time: 16:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="stylesheet" href="css/login.css" type="text/css">
    <title>注册</title>
</head>
<body>
<div style="margin: 0 20%">
    <div id="zhuce">
        <form id="form" method="POST" action="/user?type=register">
            <input type="text" name="username" id="username" placeholder="账号"/><br>
            <input type="password" name="password" id="password" placeholder="密码"/><br>
            <input type="button" value="注册" onclick="checkUsername()"/>
        </form>
    </div>
</div>
<script>

    function checkUsername() {
        var username = document.getElementById("username").value;
        var regName = new RegExp('^[a-zA-Z][a-zA-Z0-9_]{4,15}$')

        var regPass = new RegExp('^[a-zA-Z]\\w{5,17}$')
        var password = document.getElementById("password").value;
        if (!regName.test(username)) {
            alert("帐号(字母开头，允许5-16字节，允许字母数字下划线)")
            return;
        }
        if (!regPass.test(password)) {
            alert("密码(以字母开头，长度在6~18之间，只能包含字母、数字和下划线)")
            return;
        }
        //手动提交表单
        document.getElementById("form").submit()
    }
</script>
</body>
</html>
